package com.bmj.study.dao.impl;

import com.bmj.study.dao.ResumeDAO;
import com.bmj.study.entity.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("resumeDAO")
public class ResumeDAOImpl implements ResumeDAO {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void insertResume(Resume resume) {
        mongoTemplate.insert(resume, "lg_resume_datas");
    }

    @Override
    public Resume findByName(String name) {
        // 查询要构造一个 Query 对象
        Query query = new Query();
        query.addCriteria(Criteria.where("name").is(name));
        return mongoTemplate.findOne(query, Resume.class, "lg_resume_datas");
    }

    @Override
    public List<Resume> findAll() {
        return mongoTemplate.findAll(Resume.class);
    }


}
